07 September 2020



  • Introduction


  • Example of Shiny Apps


  • Deployment

Introduction

About Me





  • BSc (Mathematical Sciences)
  • MSc (Statistics)
  • PhD (Computational Statistics)
    • Prof. Nial Friel

  • PostDoc
    • Insight Centre for Data Analytics (UCD)
    • Prof. Andrew Parnell

  • Data Scientist (Clavis Insight)
    • Ecommerce analytics startup
    • Acquired by Ascential 2017

  • Senior Data Scientist (Edge by Ascential)
    • Combination of 4 companies

My Journey with Shiny

  • First created a Shiny App in 2015

My Journey with Shiny

  • First created a Shiny App in 2015
  • Second App created during Postdoc
    • Needed a way of allowing a non technical user to run my code

My Journey with Shiny

  • First created a Shiny App in 2015
    • Teaching app to help explain regression and correlation
  • Second App created during Postdoc
    • Needed a way of allowing a non technical user to run my code
  • Current Role
    • 6 Shiny apps in use internally
    • Various uses
      • Run ML algorithms
      • ETL workflows
      • Database access

My Journey with Shiny

  • First created a Shiny App in 2015
    • Teaching app to help explain regression and correlation
  • Second App created during Postdoc
    • Needed a way of allowing a non technical user to run my code
  • Current Role
    • 6 Shiny apps in use internally
    • Various uses
      • Run ML algorithms
      • ETL workflows
      • Database access
  • Personal Projects
    • Exploring and visualising data

Dashboards

Examples

Plotly

  • Graphing library
    • R, Python, JavaScript
  • Has integration with ggplot2 and shiny
  • Plots can be also be saved as HTML files or displayed within R Markdown HTML documents or presentations

library(ggplot2)
my_plot <- 
  ggplot(mpg, aes(x = displ, y = hwy, colour = class)) +
  geom_point()
my_plot

library(plotly)
my_plot <- 
  ggplot(mpg, aes(x = displ, y = hwy, colour = class)) +
  geom_point()
ggplotly(my_plot)

library(plotly)
my_plot <- 
  ggplot(mpg, aes(x = displ, y = hwy, colour = class)) +
  geom_point() + theme(plot.background = element_rect(fill = "transparent", color = NA))
ggplotly(my_plot)

app.R

library(shiny)
library(plotly)

ui <- fluidPage(
    plotlyOutput("sample_plot")
)

server <- function(input, output) {
    output$sample_plot <- renderPlotly({
        my_plot <- 
            ggplot(mpg, aes(displ, hwy, colour = class)) +
            geom_point()
        ggplotly(my_plot)
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

Plotly - Save as HTML



library(htmlwidgets)
saveWidget(ggplotly(my_plot), "~/Desktop/sample_plotly.html")

Dublin RTPI

  • Real Time Passenger Information
  • Entry for RStudio’s Shiny Contest 2019
  • Obtains data from public API
  • Displays data for multiple bus stops

URL Header Variables

Deployment

Deployment

shinyapps.io

  • Free
    • 5 applications
    • 12 active hours
  • Starter $100/yr \(\approx\) £75
    • 25 applications
    • 100 active hours
  • Basic $440/yr \(\approx\) £333
    • Unlimited applications
    • 500 active hours



  • Pros
    • Simple to deploy app
    • Almost no maintenance
    • Easy to start and stop apps
    • Visibilty on app usage
  • Cons
    • Non customisable URLs
      (without pro plan)
    • App limits
    • Usage limits

Amazon Web Services





  • Server cost
    • $94.26
      (EC2 t3.micro + 8GB storage)
    • €33.76 aboland.ie domain
    • Total €114 \(\approx\) £102





  • Pros
    • Flexibility
    • Custom URL’s
    • Can use server for other uses e.g. website, storage, API’s
  • Cons
    • Harder to deploy apps
    • Server maintenance
      • AWS management
      • Machine libraries
    • Harder to get visibility on app usage

Thank you

Appendix

Sharing Apps

Sharing - Files

  • Files
    • app.R or ui.R + server.R


  • Cons
    • Person running the app must be familiar with R
    • Potential problems with old or new library versions

Sharing - Within R Package

  • R packages/libraries can include shiny images
  • Store app in inst/shiny-examples/my_app directory
run_ShinyApp <- function() {
  appDir <- system.file("shiny-examples", "my_app", package = "footballR")
  if (appDir == "") {
    stop("Could not find example directory. Try re-installing `footballR`.", call. = FALSE)
  }
  shiny::runApp(appDir, display.mode = "normal")
}

Example

devtools::install_github("aboland/footballR")
footballR::run_ShinyApp()

Sharing - Docker

  • Docker is a very useful method of creating and running isolated versions of software
  • Build ‘images’ with specific version of R and libraries


  • Cons
    • Person needs familiarity with Docker